<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>班级列表</title>
		<script src="../../node_modules/layui/dist/layui.js"></script>
		<script src="../../node_modules/mockjs/dist/mock.js"></script>
		<link rel="stylesheet" type="text/css" href="../../node_modules/layui/dist/css/layui.css" />
		<link rel="stylesheet/less" type="text/css" href="../../src/css/style.less" />
		<script src="../../src/css/less.min.js"></script>
		<script src="../baseUrl.js"></script>
	</head>
	<body>
		<!-- 列表 -->
		<table class="layui-hide" id="test" lay-filter="list"></table>
		<!-- 列表操作栏 -->
		<script type="text/html" id="barDemo">
			<a class="layui-btn layui-btn-xs" lay-event="look">查看</a>
			<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
			<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
		</script>

		<script>
			const { table, layer } = layui;
			layui.use(function() {
				table.render({
					elem: '#test',
					url: `${baseUrl}/api/class/list/`,
					cellMinWidth: 80,
					cols: [
						[
							{ field: 'id', width: 80, title: 'ID', sort: true },
							{ field: 'className', title: '班级名称', sort: true },
							{ field: 'classType', title: '班级类型', sort: true },
							{ field: 'classTeacher', title: '班主任', sort: true },
							{ field: 'startDate', title: '开始时间', sort: true },
							{ field: 'endDate', title: '毕业时间', sort: true },
							{ fixed: 'right', title: '操作', toolbar: '#barDemo', width: 168 }
						]
					],
					response: {
						statusCode: 10000
					},
					page: true,
					parseData: function(res) { //res 即为原始返回的数据
						return {
							"code": res.code, //解析接口状态
							"msg": res.message, //解析提示文本
							"count": res.data.total, //解析数据长度
							"data": res.data.list //解析数据列表
						};
					},
				});
			});

			table.on('tool(list)', param => {
				const { data, event } = param;
				switch (event) {
					case 'look':
						window.parent.classRowData = data;
						location.href = 'studentList.html';
						break;
					case 'edit':
						let xml = new XMLHttpRequest();
						
						
						// const data = {
						// 	id:1,
						// 	className:'sssss'
						// }
						
						
						// xml.open('POST', `${baseUrl}/api/class/set/`);
						// xml.setRequestHeader('Content-type', 'application/json');
						// xml.send(JSON.stringify(data));
						// xml.onreadystatechange = function() {
						// 	if (xml.readyState === 4) {
						// 		if (xml.status === 200) {
						// 			console.log(xml.responseText)
						// 		}
						// 	}
						// }







						// layer.open({
						// 	type: 2,
						// 	title: '班级弹框',
						// 	shadeClose: true,
						// 	shade: 0.8,
						// 	area: ['380px', '90%'],
						// 	content: './tan/classTan.html' //iframe的url
						// });

						break;
					case 'del':
						break;
				}
			})
		</script>
	</body>
</html>
